package jmine.selenium.services.registry;

import jmine.tec.services.api.ActionsEnum;
import jmine.tec.services.api.Service;
import jmine.tec.services.api.factory.ServiceCreationException;
import jmine.tec.utils.Tuple;
import jmine.tec.utils.UnmodifiableTuple;
import bancosys.tec.services.implementor.ServiceImplementorAccessor;
import bancosys.tec.services.implementor.ServiceImplementorProxy;
import bancosys.tec.services.implementor.ServiceImplementorRuntime;

/**
 * Registro de serviços de Selenium implementados em Java.
 * 
 * @author Rafael Volpato
 */
public class SeleniumServicesRegistry extends AbstractServicesRegistry<Class<?>, ServiceImplementorAccessor> {

    private ServiceImplementorRuntime serviceRuntime;

    /**
     * @param serviceRuntime the serviceRuntime to set
     */
    public void setServiceRuntime(ServiceImplementorRuntime serviceRuntime) {
        this.serviceRuntime = serviceRuntime;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected Service doCreateService(ActionsEnum action, String serviceName, ServiceImplementorAccessor accessor)
            throws ServiceCreationException {
        return new ServiceImplementorProxy(accessor);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected Tuple<String, ServiceImplementorAccessor> getEntryToRegister(Class<?> clazz) {
        ServiceImplementorAccessor accessor = this.serviceRuntime.describeService(clazz);
        String keyForService = this.cacheKeyForService(accessor.getActionType(), accessor.getServiceName());
        return new UnmodifiableTuple<String, ServiceImplementorAccessor>(keyForService, accessor);
    }
}
